// src/server.js

const express = require('express');
const { sequelize } = require('./models');
const apiRoutes = require('./routes/api');
const cors = require('cors'); // 引入 CORS 中间件

const app = express();
const PORT = process.env.PORT || 3000;

app.use(cors()); // 启用 CORS，允许所有域访问

app.use(express.json());

app.use('/api', apiRoutes);

sequelize.sync().then(() => {
    app.listen(PORT, () => {
        console.log('\x1b[35m%s\x1b[0m', `Server is running on port ${PORT}`);
    });
});